extends ../layouts/default

include ../mixins/commenting
include ../mixins/post

block content
	if !post
		.jumbotron.text-center
			h2 Invalid post...
			p.lead Please check the url and try again
	else
		.row
			.col-md-8.col-md-offset-2
				p: a(href='/blog').text-muted &larr; back to the blog
				hr
				article
					header
						h1= post.name
						if post.image.exists
							div(style="margin-bottom: 20px; margin-top: 20px;")
								img(src=post._.image.fit(750,500)).img-responsive
						div
							p.text-muted.text-small Posted 
								if post.publishedDate
									| on 
									time(datetime=post.publishedDate)=post._.publishedDate.format('MMMM Do, YYYY')
								if post.categories && post.categories.length
									|  in 
									each cat, cat_i in post.categories
										a(href='/blog/' + cat.key)= cat.name
										if cat_i < post.categories.length - 1
											| , 
										else
											|  
								if post.author
									| by #{post.author.name.full}
						hr
						!= post.content.full
					//-comments
					div
						+comment-form()
						+comment-thread(comments)


block page-js
	script.
		jQuery(function($) {
			
			var comments = $('#comments');
			var input = $('.comment-field-input');
			var submit = comments.find('button[type=submit]');

			
			// Scroll to comments and focus input field
			function scrollToComments(e) {
				
				e.preventDefault();
				
				$('html, body').animate({ scrollTop: comments.offset().top }, 250);
				
				input.eq(0).focus();
			}
			$('[href="#comments"]').click( scrollToComments );
			
			
			
			// Check if field has content: enable/disable submit. Disable by default
			submit.attr('disabled','disabled');
			input.keyup(function() {
				if ($.trim($(this).val())) {
					submit.removeAttr('disabled');
				} else {
					submit.attr('disabled','disabled');
				}
			});
		});
